package com.hc.model.utils;

import com.hc.DTO.MessageDTO;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

public class MessageModel {
	public static MessageModel instance;

	public static MessageModel getInstance() {
		if (instance == null)
			instance = new MessageModel();
		return instance;
	}

	public MessageDTO getMessage(Context context) {
		MessageDTO dto = new MessageDTO();
		String sql = "SELECT * FROM message";
		DBHelper db = new DBHelper(context);
		Cursor c = db.Excutequery(sql);
		while (c.moveToNext()) {
			dto.setFlag(c.getInt(c.getColumnIndex("flag")));
			dto.setDatemessage(c.getString(c.getColumnIndex("datemessage")));
		}
		c.close();
		db.close();

		return dto;
	}

	public boolean UpdateFlag(MessageDTO dto, Context context) {
		boolean flag = false;
		// String sql = "UPDATE changelog SET Id=" + id;
		DBHelper db = new DBHelper(context);
		ContentValues values = new ContentValues();
		values.put("flag", dto.getFlag());
		values.put("datemessage", dto.getDatemessage());
		flag = db.ExcuteUpdate(null, "message", values, "1 = 1", null);
		db.close();
		return flag;
	}
}
